home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 038a / qbsbkit.zip / CTVIN.BAS next >
BASIC Source File  |  1991-05-05  |  3KB  |  121 lines

  1.  
  2. 'QBXSBC CTVIN.BAS
  3. 'voice input example for the SoundBlaster routines
  4. '5-May-1991
  5.  
  6. DEFINT A-Z
  7.  
  8. REM $INCLUDE: 'QBXIOL.BI'
  9. REM $INCLUDE: 'QBXCTV.BI'
  10. REM $INCLUDE: 'QBXFMI.BI'
  11.  
  12. TYPE CVheaderTYPE
  13. FileID AS STRING * 20
  14. DataStart AS INTEGER
  15. Version AS INTEGER
  16. VoiceID AS INTEGER
  17. END TYPE '26
  18. DIM HDR AS CVheaderTYPE
  19.  
  20. HDR.FileID = "Creative Voice File" + CHR$(26)
  21. HDR.DataStart = 26
  22. HDR.Version = 1 * 256 + 0
  23. HDR.VoiceID = &H1133
  24.  
  25. CLS
  26. PRINT "CTVIN.BAS for QBXSBC"
  27. PRINT
  28. PRINT "CTVport   stat:"; CTVport(&H220)
  29. PRINT "CTVirq    stat:"; CTVirq(&H7)
  30. stat = CTVdetect
  31. PRINT "CTVdetect stat:"; stat
  32. PRINT "CTVver    stat:"; CTVver(soft, hard);
  33. PRINT "  S/W:"; RTRIM$(STR$(soft \ 256)); "."; LTRIM$(STR$(soft MOD 256));
  34. PRINT "  H/W:"; RTRIM$(STR$(hard \ 256)); "."; LTRIM$(STR$(hard MOD 256))
  35. IF stat THEN
  36.    SELECT CASE stat
  37.    CASE 1
  38.       PRINT "SBC failed or is not installed"
  39.    CASE 2
  40.       PRINT "SBC I/O R/W failed"
  41.    CASE 3
  42.       PRINT "SBC DMA failed"
  43.    CASE ELSE
  44.       PRINT "Unexpected failure code"
  45.    END SELECT
  46.    SYSTEM
  47. END IF
  48.  
  49. '12000 samples/second, 5 seconds of recording
  50. SampleRate = 12000
  51. MaxTime = 2
  52. bytes& = 1& * SampleRate * MaxTime
  53.  
  54. 'allocate a buffer large enough for the 5 seconds of voice data
  55. 'and 26 extra bytes for the header (VOXKIT compatible header)
  56. 'we can then use VOXKIT to silence-pack and then 4-bit pack
  57.  
  58. REDIM vocbuff(0 TO (bytes& + 26) \ 2) AS INTEGER
  59. vseg = VARSEG(vocbuff(0))
  60. voff = VARPTR(vocbuff(0))
  61.  
  62. PRINT
  63. INPUT "Press <Enter> to begin recording", a$
  64.  
  65. 'turn voice speaker off
  66. stat = CTVspeaker(0)
  67.  
  68. 'and record (that simple)
  69. stat = CTVinput(SampleRate, bytes&, vseg, voff + 26)
  70.  
  71. IF stat = 0 THEN
  72.  
  73.    PRINT "Your on!"
  74.    'wait until sampling done (RECORDING!)
  75.    DO
  76.       stat = CTVstatus
  77.    LOOP WHILE stat
  78.  
  79. END IF
  80.  
  81. stat = CTVuninstall
  82. PRINT "done."
  83.  
  84. INPUT "Press ENTER to begin playback"; a$
  85. PRINT "CTVspeaker on  stat:"; CTVspeaker(1)
  86. PRINT "CTVoutput      stat:"; CTVoutput(vseg, voff + 26)
  87. DO
  88.    stat = CTVstatus
  89. LOOP WHILE stat
  90. PRINT "CTVuninstall   stat:"; CTVuninstall
  91.  
  92. DO: LOOP WHILE INKEY$ <> ""
  93.  
  94. INPUT "Save to filename:", pathname$
  95. IF LEN(pathname$) THEN
  96.  
  97.    'Create the voice file (must not already exist)
  98.    stat = CreateFile(pathname$ + CHR$(0), 0)
  99.    IF stat THEN PRINT "Create:"; stat: STOP
  100.  
  101.    'Open it
  102.    stat = OpenDevice(pathname$ + CHR$(0), 2, handle, flen&)
  103.    IF stat THEN PRINT "Open:"; stat: STOP
  104.  
  105.    'Write header data
  106.    stat = WriteDevice(handle, 0, LEN(HDR), VARSEG(HDR), VARPTR(HDR))
  107.    IF stat THEN PRINT "Write:"; stat
  108.  
  109.    'Write voice data
  110.    stat = WriteDevice(handle, LEN(HDR), bytes&, vseg, voff + 26)
  111.    IF stat THEN PRINT "Write:"; stat
  112.  
  113.    'Close it
  114.    stat = CloseDevice(handle)
  115.    IF stat THEN PRINT "Close:"; stat: STOP
  116.  
  117.    PRINT "done."
  118.  
  119. END IF
  120.  
  121.